// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
    env:"tfjkp-0ge80vu9ea710148"
})

// 云函数入口函数
exports.main = async (event, context) => {
    //能量的获取从服务器拉去下来
    const db = cloud.database();
    const _ = db.command;
    let { OPENID, APPID, UNIONID } = await cloud.getWXContext()

    return new Promise((resovle, reject) => {
        db.collection('enerayBall').where(_.and({openid:OPENID},{_isFetch:false})).get().then(res => {

            db.collection('userInfo').where({openid:OPENID}).get().then(userInfo =>{
            
                var userData = {
                    "enerayBall":res.data,
                    "scene":"cloud://cloud1-2gcb4u0bc9e3a9d4.636c-cloud1-2gcb4u0bc9e3a9d4-1305195523/heya.png",
                    "skin":"cloud://cloud1-2gcb4u0bc9e3a9d4.636c-cloud1-2gcb4u0bc9e3a9d4-1305195523/tree.png",
                    "userInfo":userInfo.data
                }
                resovle(userData)
            })
        })
    })
  
}